-- 当currentSeq = maxSeq时 数据库需要增加stepSize 判断条件为 current < 0

local curPrefixKey = KEYS[1]
local maxPrefixKey = KEYS[2]
local stepSize = KEYS[3]
local currentSeq = redis.call('incr', curPrefixKey)
local maxSeq = redis.call('get', maxPrefixKey)
if (not maxSeq) then
    -- 防止key被删除
    redis.call('incr',(math.ceil(currentSeq / stepSize) + 1) * stepSize)
    return currentSeq
end
if currentSeq >= tonumber(maxSeq) then
    redis.call('incrby', maxPrefixKey, stepSize)
    return -currentSeq
else
    return currentSeq;
end